Naming conventions
Pascal case
Use pascal casing ("PascalCasing") when naming a class, record, method or struct .
// Class
public class AlarmController
{
// Method
public IActionResult CreateAlarm()
{
}
}
// Record
public record PhysicalAddress(
string Street,
string City,
string StateOrProvince,
string ZipCode);
// Struct
public struct ValueCoordinate
{
}
When naming an interface, use pascal casing in addition to prefixing the name with an I. This clearly indicates to consumers that it's an interface.
public interface IWorkerQueue
{
}
When naming public members of types, such as fields, properties, events, methods, and local functions, use pascal casing.
public class ExampleEvents
{
// A public field, these should be used sparingly
public bool IsValid;
// An init-only property
public IWorkerQueue WorkerQueue { get; init; }
// An event
public event Action EventProcessing;
// Method
public void StartEventProcessing()
{
// Local function
static int CountQueueItems() => WorkerQueue.Count;
}
}
When working with static fields that are private or internal, use pascal casing.
public class DataService
{
private static int HeartBeat;
[ThreadStatic]
private static TimeSpan ElapsedTimeSpan;
}
Camel case
Use camel casing ("camelCasing") when naming private or internal fields and prefix them with _.
public class DataService
{
private IWorkerQueue _workerQueue;
}
When writing method parameters, use camel casing.
public T SomeMethod<T>(int someNumber, bool isValid)
{
}